
// TopoOptimizeDlg.h : header file
//

#pragma once
#define MINI 0.0000000001f
class CVectorKey
{
private:
	static UINT s_nDimension;
public:
	CVectorKey()
		:m_rgId(s_nDimension,0.0f)
	{

	};
	CVectorKey(const CVectorKey& tmp)
		:m_rgId(tmp.m_rgId)
	{

	};
	static void SetDimension(const UINT nDimension)
	{
		s_nDimension=nDimension;
	};
	vector<float> m_rgId;
	static float GetDistance(const CVectorKey& cLeft,const CVectorKey& cRight)
	{
		double dTop =0.0,dBottom1 = 0.0,dBottom2 = 0.0;
		for(unsigned int i = 0;i<s_nDimension;i++)
		{
			dTop+=cLeft.m_rgId[i]*cRight.m_rgId[i];
			dBottom1+=cLeft.m_rgId[i]*cLeft.m_rgId[i];
			dBottom2+=cRight.m_rgId[i]*cRight.m_rgId[i];
		}
		float fRes = (float)(dTop/sqrt(dBottom1*dBottom2));

		return /*1.0f-*/fRes;
	};
	static int Compare(const CVectorKey& cLeft,const CVectorKey& cRight)
	{
		for(int i=s_nDimension-1;i>=0;i--)
		{
			if(abs(cLeft.m_rgId[i],cRight.m_rgId[i])<MINI)
			{
				continue;
			}
			else
			{
				if(cLeft.m_rgId[i]>cRight.m_rgId[i])
				{
					return i+1;
				}
				else
				{
					return -1-i;
				}
			}
		}
		return 0;
	};
};

// CTopoOptimizeDlg dialog
class CTopoOptimizeDlg : public CDialog
{
// Construction
public:
	CTopoOptimizeDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_TOPOOPTIMIZE_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
private:
	unsigned int m_nSimpleNumber;
	unsigned int m_nNodeNumber;
	vector<vector<int>> m_rgDistanceTable;
	unsigned int m_nPivotNumber;
public:
	afx_msg void OnBnClickedButtonImportNodeLatency();
	afx_msg void OnBnClickedButtonDrawPoint();
	afx_msg void OnBnClickedButtonDrawLine();
	UINT m_nGranularity;
};
